# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dwd.January.dwd_tmsnew_shipment_stop_dt import jms_dwd__dwd_tmsnew_shipment_stop_dt
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dwd.tab.dwd_tab_barscan_centerarrival_base_dt import jms_dwd__dwd_tab_barscan_centerarrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_sitearrival_base_dt import jms_dwd__dwd_tab_barscan_sitearrival_base_dt
from jms.dwd.tab.dwd_tab_barscan_centersend_base_dt import jms_dwd__dwd_tab_barscan_centersend_base_dt
from jms.dwd.tab.dwd_tab_barscan_unloading_base_dt import jms_dwd__dwd_tab_barscan_unloading_base_dt
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from jms.dwd.tab.dwd_tab_barscan_warehousing_base_dt import jms_dwd__dwd_tab_barscan_warehousing_base_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.tab.dwd_dependent_hi.dwd_yl_tmsnew_tms_shipment_base_hf_23 import dwd_yl_tmsnew_tms_shipment_base_hf_23

from jms.time_sensor.time_after_03_30 import time_after_03_30

jms_dm__dm_shipno_change_detail_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_shipno_change_detail_dt',
    pool_slots=7,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dm__dm_shipno_change_detail_dt_{{ execution_date | cst_ds }}',  # yarn 任务名称
    execution_timeout=timedelta(minutes=90),
    email=['wangbiao@yl-scm.com','yl_bigdata@yl-scm.com'],
    driver_cores=2 , 
    driver_memory='3G' , 
    executor_cores=3 ,
    executor_memory='8G' ,
    num_executors=50 ,
    conf={'spark.dynamicAllocation.enabled'                  : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                    : 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 60 ,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          'spark.sql.shuffle.partitions'                     : 2400,
          'spark.default.paralleism'                         : 2400,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 180,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 20 个分区
              },
    java_class='com.yunlu.bigdata.jobs.export.ShipnoWeightChangeData',  # spark 主类
    #application='hdfs:///user/spark/work/dm/chenhongping/shipno_change_detail/ShipnoWeight.jar',
    # application='hdfs:///scheduler/jms/spark/chp/shipno_change_detail/ShipnoWeight.jar',
    application='hdfs:///scheduler/jms/spark/chp/shipno_change_detail_2/ShipnoWeight.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}'],  # 参数dt 2020-10-26
)

# 设置依赖
jms_dm__dm_shipno_change_detail_dt << [
    dwd_yl_tmsnew_tms_shipment_base_hf_23,
    jms_dwd__dwd_tmsnew_shipment_stop_dt,
    jms_dwd__dwd_tab_barscan_loading_base_dt,
    jms_dwd__dwd_tab_barscan_centerarrival_base_dt,
    jms_dwd__dwd_tab_barscan_sitearrival_base_dt,
    jms_dwd__dwd_tab_barscan_centersend_base_dt,
    jms_dwd__dwd_tab_barscan_unloading_base_dt,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_tab_barscan_warehousing_base_dt,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    time_after_03_30
]
